package ru.pb.game.network.engine.client.packets.receivable;

import ru.pb.game.data.xml.holders.ChannelHolder;
import ru.pb.game.network.engine.client.packets.FromClientToGameServerPacket;
import ru.pb.game.network.engine.client.packets.sendable.PROTOCOL_ROOM_GET_LOBBY_USER_LIST_ACK;
import ru.pb.game.objects.model.CHANNEL;
import ru.pb.game.objects.model.players.Player;
import ru.pb.game.objects.storage.ObjectsStorage;
import ru.pb.global.utils.ArrayUtils;
import ru.pb.global.utils.Rnd;

/**
 * @author: DarkSkeleton
 * @version: 1.00
 */
public class PROTOCOL_ROOM_GET_LOBBY_USER_LIST_REQ extends FromClientToGameServerPacket
{
	public PROTOCOL_ROOM_GET_LOBBY_USER_LIST_REQ()
	{

	}

	@Override
	public void readImpl()
	{}

	@Override
	public void runImpl()
	{
		Player p = getPlayer();
		if(p != null)
		{
			CHANNEL ch = ChannelHolder.getChannel(getClient().getChannelId());
			int count_users_list = 0;

			if(ch.getAllPlayers().size() == 0)
				count_users_list = 0;
			else if(ch.getAllPlayers().size() > 8)
				count_users_list = 8;
			else
				count_users_list = ch.getAllPlayers().size();

			//Player[] temp = new Player[count_users_list];

			//for(int i = 0; i < count_users_list; i++)
			//{
			//	int random = Rnd.get(ch.getAllPlayers().toArray());
			//	if( !ArrayUtils.isInArray(temp, random))
			//	{
			//		Player rp = ObjectsStorage.getInstance().getPlayer(random);
			//		if(rp != null)
			//			temp[i] = rp;
			//		else
			//			i--;
			//	}
			//	else
			//		i--;
			//}
			//p.sendPacket(new PROTOCOL_ROOM_GET_LOBBY_USER_LIST_ACK(temp));
		}
	}
}